void checkSerialNumberExists(int serialNumber) {
  if (serialNumber > 0) {
    for (int i = 0; i < serialsSeen.length; i++) {
      if (serialsSeen[i] == serialNumber) {
        serialsSeenCounter[i] = serialsSeenCounter[i] + 1;
        return;
      }
    }
    // We didn't find the number in our existing array of serial numbers, so add it
    addSerialNumber(serialNumber);
    if (debug) { println("serial number added: " + serialNumber + " serialsSeen.length=" + serialsSeen.length); }
    return;
  }
}

void addSerialNumber(int newSerialNumber) {
  if (serialsSeen[0] != 0) {
    serialsSeen = expand(serialsSeen, (serialsSeen.length + 1));
    serialsSeenCounter = expand(serialsSeenCounter, (serialsSeenCounter.length + 1));
  }
  serialsSeen[serialsSeen.length - 1] = newSerialNumber;
  serialsSeenCounter[serialsSeenCounter.length - 1] = 1;
}

